package com.smart.admin.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.admin.common.request.BrandRequestParams;
import com.smart.admin.common.vo.BrandVo;
import com.smart.admin.entity.Brand;
import com.smart.admin.mapper.BrandMapper;
import com.smart.admin.service.BrandService;
import com.smart.common.utils.CommonBeanUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@DS("smart_product")
public class BrandServiceImpl implements BrandService {
    @Resource
    private BrandMapper brandMapper;


    @Override
    public int save(BrandRequestParams brandRequestParams) {
        Brand brand = new Brand();
        BeanUtils.copyProperties(brandRequestParams, brand);
        return brandMapper.insert(brand);
    }

    @Override
    public BrandVo getBrand(int id) {
        Brand brand = brandMapper.selectById(id);
        BrandVo brandVo = new BrandVo();
        CommonBeanUtils.copyProperties(brandVo, brand);
        return brandVo;
    }

    @Override
    public Page<Brand> list(int page, int size) {
        Page<Brand> brandPage = brandMapper.selectPage(new Page<>(page, size), null);
        return brandPage;
    }

    @Override
    public int update(BrandRequestParams brandRequestParams) {
        Brand brand = new Brand();
        CommonBeanUtils.copyProperties(brandRequestParams, brand);
        int update = brandMapper.updateById(brand);
        return update;
    }

    @Override
    public int remove(int id) {
        return brandMapper.deleteById(id);
    }
}
